{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="{% static 'layui/css/layui.css' %}" rel="stylesheet">
    <script src=" {% static 'layui/layui.js' %}"></script>
    {#    <script src=" {% static 'js/adddevices.js' %}"></script>#}
    <title>增加设备</title>
</head>
<body>
<form class="layui-form" action="" lay-filter="form-table">
    {% csrf_token %}
    <div class="layui-form-item">
        <label class="layui-form-label">设备名</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="text" class="layui-input" lay-verify="device_name" name="device_name" placeholder="设备名" aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">设备类型</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="text" class="layui-input" lay-verify="device_type" name="device_type" placeholder="设备类型" aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">设备平台</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="text" class="layui-input" lay-verify="device_platform" name="device_platform" placeholder="设备平台"
                   aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">CPU类型</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="text" class="layui-input" name="cpu_type" placeholder="CPU类型" aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内存</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="text" class="layui-input" name="mem_num" lay-verify="number"  placeholder="内存" aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">高低端</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="text" class="layui-input" name="level" placeholder="高低端" aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否热门</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="radio" name="hot" value="1" title="是" checked="">
            <input type="radio" name="hot" value="0" title="否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">设备状态</label>
        <div class="layui-input-block">
            <input type="text" class="layui-inputl" name="state" placeholder="设备状态" aria-describedby="sizing-addon1">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">借还</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <input type="radio" name="borrow" value="1" title="可借" checked=" ">
            <input type="radio" name="borrow" value="0" title="已借出">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">版本</label>
        <div class="layui-input-block">
{#            //name标签一定需要有，后面form表单的提交中，data的数值就是通过那么的值来拿的#}
            <select id="version" name="version">
                <option value=""></option>
                <option value="7.0">7.0</option>
                <option value="8.0">8.0</option>
                <option value="9.0">9.0</option>
                <option value="10.0">10.0</option>
                <option value="11.0">11.0</option>
                <option value="12.0">12.0</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="reset" class="layui-btn layui-btn-normal">取消</button>
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="formDemo">确定</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        $ = layui.jquery;
        {#var data = form.val('form-table');#}
        //表单验证
        form.verify({
            device_name:function (value) {
                if (value == null || value == ""){
                    return '设备名字不能为空！';
                }
            }
            ,device_type:function (value) {
                if(value == null || value == ""){
                    return '设备类型不能为空！';
                }
            }
        });

        form.on('submit(formDemo)',function (data) {
            console.log('data:',data)
            $.ajax({
                rul: '/insertdevice',
                type: 'POST',
                data: data.field,
                {#dataType: 'json',#}
                success: function (re) {
                    layer.msg('添加成功');
                    layer.close();//关闭当前弹出层
                    parent.location.reload();//刷新父页面
                }
            })
            return false;
        });

    })

</script>
</body>
</html>